package com.kaifamiao.buffer;

/**
 * 1、StringBuffer是 线程安全(thread-safe) 的、StringBuilder 不是 线程安全 的
 * 2、StringBuilder也没有重写 hashCode 和 equals 方法
 */
public class TestStringBuilder {

    public static void main(String[] args) {

        StringBuilder builder = new StringBuilder();
        System.out.println( builder.capacity() + " , " + builder.length() );

        builder.append( "云创动力" );
        builder.append( '开' );
        builder.append( '发' );
        builder.append( '喵' );
        System.out.println( builder );

        builder.insert(4, '·' );
        System.out.println( builder );

        System.out.println( "capacity: " + builder.capacity() + ", length: " + builder.length() );
        builder.trimToSize();
        System.out.println( "capacity: " + builder.capacity() + ", length: " + builder.length() );

        System.out.println( "- ".repeat( 20 ) );

        String str = builder.toString();

        StringBuilder first = new StringBuilder( str );
        System.out.println( builder.equals( first ) ); // false
        // String类中的实例方法:
        // boolean contentEquals(CharSequence)
        System.out.println( str.contentEquals( builder ));

        StringBuffer second = new StringBuffer( str );
        System.out.println( second.equals(builder) ); // false
        // String类中的实例方法:
        // boolean contentEquals(StringBuffer)
        System.out.println( str.contentEquals( second ) ); // true

    }

}
